package com.myjava.servlet;

import com.alibaba.fastjson.JSON;
import com.myjava.bean.Person;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

@WebServlet("/axios01")
public class Axios01Servlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        String age = req.getParameter("age");
        System.out.println("name = "+name);
        System.out.println("age = "+age);

            List<Person> list = new LinkedList<>();
            list.add(new Person(1,"大胖",22));
            list.add(new Person(2,"二狗",23));
            list.add(new Person(3,"三瘦",24));
            //做出相应
            //转换成json数据
            String s = JSON.toJSONString(list);
            resp.getWriter().println(s);
    }
}
